package com.ruoyi.merchandise.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.merchandise.domain.Product;
import com.ruoyi.merchandise.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.merchandise.mapper.TbOrderinfoMapper;
import com.ruoyi.merchandise.domain.TbOrderinfo;
import com.ruoyi.merchandise.service.ITbOrderinfoService;

import javax.annotation.Resource;

/**
 * 订购信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-21
 */
@Service
public class TbOrderinfoServiceImpl implements ITbOrderinfoService 
{
    @Resource
    private TbOrderinfoMapper tbOrderinfoMapper;
    @Resource
    private ProductMapper productMapper;
    /**
     * 查询订购信息
     * 
     * @param id 订购信息主键
     * @return 订购信息
     */
    @Override
    public TbOrderinfo selectTbOrderinfoById(Long id)
    {
        return tbOrderinfoMapper.selectTbOrderinfoById(id);
    }

    /**
     * 查询订购信息列表
     * 
     * @param tbOrderinfo 订购信息
     * @return 订购信息
     */
    @Override
    public List<TbOrderinfo> selectTbOrderinfoList(TbOrderinfo tbOrderinfo)
    {

        List<TbOrderinfo> orderList = tbOrderinfoMapper.selectTbOrderinfoList(tbOrderinfo);
        Product product = new Product();
        List<Product> productList = productMapper.selectProductList(product);
        orderList.stream().map(order->{
            productList.stream().forEach(p -> {
                if(p.getpCode().equals(order.getProductId())){
                    order.setProductId(p.getpName());
                }
            });
            return order;
        }).collect(Collectors.toList());
        return orderList;
        //return tbOrderinfoMapper.selectTbOrderinfoList(tbOrderinfo);
    }

    /**
     * 新增订购信息
     * 
     * @param tbOrderinfo 订购信息
     * @return 结果
     */
    @Override
    public int insertTbOrderinfo(TbOrderinfo tbOrderinfo)
    {
        return tbOrderinfoMapper.insertTbOrderinfo(tbOrderinfo);
    }

    /**
     * 修改订购信息
     * 
     * @param tbOrderinfo 订购信息
     * @return 结果
     */
    @Override
    public int updateTbOrderinfo(TbOrderinfo tbOrderinfo)
    {
        return tbOrderinfoMapper.updateTbOrderinfo(tbOrderinfo);
    }

    /**
     * 批量删除订购信息
     * 
     * @param ids 需要删除的订购信息主键
     * @return 结果
     */
    @Override
    public int deleteTbOrderinfoByIds(Long[] ids)
    {
        return tbOrderinfoMapper.deleteTbOrderinfoByIds(ids);
    }

    /**
     * 删除订购信息信息
     * 
     * @param id 订购信息主键
     * @return 结果
     */
    @Override
    public int deleteTbOrderinfoById(Long id)
    {
        return tbOrderinfoMapper.deleteTbOrderinfoById(id);
    }
}
